﻿using System;
using NUnit.Framework;

namespace Azalea.Test.ORMap
{
    [TestFixture]
    public class CommandBuilderTester : Config
    {
        [Test]
        public void TestDelete()
        {
            _cmdBuilder
                .Delete()
                .Table("ANONYMIZATION_LOG")
                .Done()
                .Done(false);

            Console.WriteLine(_cmdBuilder.ToString());

            _cmdBuilder.Done(true);
            _cmdBuilder.Delete().Table("ANONYMIZATION_LOG")
                .Where()
                .Equals("ID", -1)
                .Or()
                .NotEquals("ID", -1)
                .And()
                .In("ID", new object[] {-2, -3})
                .And()
                .GreaterThan("ID", -1)
                .And()
                .GreaterThanOrEquals("ID", -1)
                .And()
                .IsNull("ID")
                .And()
                .IsNotNull("ID")
                .And()
                .LessThan("ID", -1)
                .And()
                .LessThanOrEquals("ID", -1)
                .And()
                .Like("ID", "1%")
                .And()
                .LeftBrace()
                .NotLike("ID", "%1")
                .RightBrace()
                .Done()
                .Done(false);

            Console.WriteLine(_cmdBuilder.ToString());
        }

        [Test]
        public void TestInsert()
        {
            _cmdBuilder.Insert().Table("ANONYMIZATION_LOG")
                .Value("ID", -1)
                .Value("CUSTOMER_ID", 34031)
                .Value("RULE_GROUP_ID", 1)
                .Done()
                .Done(true);

            Console.WriteLine(_cmdBuilder.ToString());
        }

        [Test]
        public void TestUpdate()
        {
            _cmdBuilder.Update().Table("ANONYMIZATION_LOG")
                .Set("IS_SUCCESS", 1)
                .Set("IS_APPROVED", 0)
                .Where()
                .Equals("ID", -1)
                .Done()
                .Done(false);

            Console.WriteLine(_cmdBuilder.ToString());
        }
    }
}